package com.ai.demo.config;

import com.ai.demo.contant.SystemContants;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ui.Model;

@Configuration
public class CommonConfiguration {
    @Bean
    public ChatMemory  chatMemory() {
        return new InMemoryChatMemory();
    }
    @Bean
    public ChatClient  chatClient(OllamaChatModel model,  ChatMemory chatMemory) {
        return ChatClient
                .builder(model)
                .defaultSystem("你是一个可爱有热心的助手，请你以小团团的身份来回答问题")
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory))   //1. 配置日志  ,实现会话记忆功能
                .build();
    }
//    哄哄机器人游戏
    @Bean
    public ChatClient  gameChatClient(OpenAiChatModel model, ChatMemory chatMemory) {
        return ChatClient
                .builder(model)
                .defaultSystem(SystemContants.SYSTEN_GAME_PROMPT)   //设定提示词，系统角色和身份
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory))   //1. 配置日志  ,实现会话记忆功能
                .build();
    }

}
